package com.java.admin.employeeInfo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.database.entity.Employeeinfo;
import com.java.database.mapper.EmployeeinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Service
@Transactional
public class EmployeeService {
    @Autowired
    private EmployeeinfoMapper employeeinfoMapper;
    /**
     *查询员工信息
     */
   public PageInfo queryEmployeeinfo(String keyword, String page){
       if(page==null||"".equals(page)){
          page="1";
       }
       if(keyword==null||"".equals(keyword)){
           keyword="";
       }
       //当前页和现实条数
       PageHelper.startPage(Integer.parseInt(page),3);
       List<Employeeinfo> employeeinfos = employeeinfoMapper.queryEmployeeinfo(keyword);
       if(employeeinfos==null){
           throw new RuntimeException("没有员工信息！");
       }
       PageInfo pageInfo = new PageInfo(employeeinfos);
       return  pageInfo;
   }
    /**
     * 添加员工信息
     */
    public   void addemployeeInfo(Employeeinfo employeeinfo){
        employeeinfoMapper.insert(employeeinfo);
    }
    /**
     * 删除员工
     */
    public  void daletemployeeInfo(String employeeid){
        if(employeeid==null||"".equals(employeeid)){
          throw  new RuntimeException("没有拿到该员工ID");
        }
         employeeinfoMapper.deleteByPrimaryKey(Integer.parseInt(employeeid));
    }

    /**
     * 修改
     */
    public void updatEmployeeid(Employeeinfo employeeinfo){
         employeeinfoMapper.updatEmployee(employeeinfo);
    }

    /**
     * 通过ID查询
     */
    public  Employeeinfo queryId(String employeeid){
        if(employeeid==null||"".equals(employeeid)){
          throw  new RuntimeException("ID为空！");
        }
        Employeeinfo employeeinfo = employeeinfoMapper.queryEmployeeId(Integer.parseInt(employeeid));
        if(employeeinfo==null){
          throw new RuntimeException("查询失败！");
        }
        return employeeinfo;
    }

    /**
     * 查询所有的维修人员
     * @return
     */
    public List<Employeeinfo> queryEmployee(){
        List<Employeeinfo> employeeinfos = employeeinfoMapper.selectAllemployee();
        return employeeinfos;

    }
    /**
     * 批量删除
     */
    public  void batchDeleteEmployee(int [] employeeid){
        employeeinfoMapper.batchDeleteEmployee(employeeid);
    }


}
